package com.niuwa.p2p.service.impl.channel;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.niuwa.p2p.dao.channel.CataLogFileDao;
import com.niuwa.p2p.entity.channel.CataLogFile;
import com.niuwa.p2p.entity.channel.CataLogFileKey;
import com.niuwa.p2p.entity.user.User;
import com.niuwa.p2p.service.channel.ICataLogFileService;
@Service 
public class CataLogFileImpl implements ICataLogFileService{
	@Autowired
	private CataLogFileDao cataLogFileDao;
	/**
	 * 保存借款文件記錄
	 * @param cataLogFileKey 
	 */
	@Override
	public void saveCatalogFile(String[] fileIDs, String catalogNo,
			User currentUser,  String corpCode) {
		for (int i = 0; i < fileIDs.length; i++) {
			CataLogFile cataLogFile = new CataLogFile();
			cataLogFile.setCatalogCode(catalogNo);
			cataLogFile.setFileId(fileIDs[i]);
			cataLogFile.setOperator(currentUser.getId());
			cataLogFile.setOperatorName(currentUser.getUserName());
			cataLogFile.setCreateTime(new Date());
			cataLogFile.setCorpCode(corpCode);
			cataLogFile.setDelFlag("N");
			cataLogFileDao.insert(cataLogFile);
		}
		
	}

	
	/**
	 * 根据条件查询借款文件
	 * @param catalogNo
	 * @return
	 */
	@Override
	public List<CataLogFile> getCatalogFilesByCatalogNo(String catalogNo,String corpCode) {
		CataLogFileKey c=new CataLogFileKey();
		c.setCatalogCode(catalogNo);
		c.setCorpCode(corpCode);
		return cataLogFileDao.queryCataLogFiles(c);
	}
	/**
	 * 假删除借款文件
	 * @param catalogNo
	 */
	@Override
	public void updateCatalogFiles(String catalogNo, String fileId,String corpCode) {
		CataLogFile catalogfile=new CataLogFile();
		catalogfile.setDelFlag("Y");
		catalogfile.setCatalogCode(catalogNo);
		catalogfile.setFileId(fileId);
		catalogfile.setCorpCode(corpCode);
		cataLogFileDao.updateByPrimaryKeySelective(catalogfile);
	}
}
